//
// Created by squbirreland on 2021/11/5.
//
#include "generic.h"
#include "string.h"
#include "stdlib.h"

void cpp_swap(void *p1, void *p2, usize size) {
    char buffer[size];
    memcpy(buffer, p1, size);
    memcpy(p1, p2, size);
    memcpy(p2, buffer, size);
}

struct Array *cpp_transfer_data(void const *p, usize type_size) {
    struct Array *byte_array = new_array(type_size, 1);
    for (usize i = 0; i < type_size; ++i) {
        array_push(byte_array, (p + i));
    }
    return byte_array;
}

void *cpp_transfer_back(struct Array const*byte_array) {
    void *p = malloc(byte_array->size);
    memcpy(p, byte_array->array_p, byte_array->size);
    return p;
}